<script setup lang="ts">
import { reactive, ref } from 'vue'
import type { TabsPaneContext } from 'element-plus'
import { useAmsStore } from '@/stores/ams'
import { getLogDetail } from '@/api/ams'

const amsStore = useAmsStore()

const activeName = ref('base')

const idpLogContent = ref({})

const serviceList = ref([])
const bootList = ref([])

const handleTabsClick = (tab: TabsPaneContext, event: Event) => {
  console.log(tab, event)
  activeName.value = tab.paneName as string
  getLogDetail(activeName.value, amsStore.currClient.id).then((res) => {
    console.log(res)
    switch (res.logCode) {
      case 'cpu':
        idpLogContent.value = JSON.parse(res.logContent)[0]
        break
      case 'memory':
        idpLogContent.value = JSON.parse(res.logContent)
        break
      case 'disk':
        idpLogContent.value = JSON.parse(res.logContent)
        break
      case 'logicDisk':
        idpLogContent.value = JSON.parse(res.logContent)
        break
      case 'board':
        idpLogContent.value = JSON.parse(res.logContent)[0]
        break
      case 'sys':
        idpLogContent.value = JSON.parse(res.logContent)[0]
        break
      case 'allMac':
        idpLogContent.value = JSON.parse(res.logContent)
        break
      case 'service':
        serviceList.value = JSON.parse(res.logContent)
        break
      case 'boot':
        bootList.value = JSON.parse(res.logContent)
        break
    }
  })
}
</script>

<template>
  <el-dialog v-model="amsStore.logDetailsDialog" title="日志详情" width="60%">
    <el-tabs
      type="border-card"
      tab-position="left"
      @tab-click="handleTabsClick"
      v-model="activeName"
    >
      <el-tab-pane label="资产信息" name="base">
        <el-descriptions class="margin-top" title="数据来源与固资系统" :column="1" border>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              资产编号
            </template>
            010294-2IU45-HJUAHNR
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              采购价格
            </template>
            5000 RMB
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              税率
            </template>
            17%
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              采购时间
            </template>
            2025-06-01 12:12:12
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              登记时间
            </template>
            2025-06-01 12:12:12
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              报废时间
            </template>
            2025-06-01 12:12:12
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="CPU信息" name="cpu">
        <el-descriptions class="margin-top" title="数据来源与插件: cpu" :column="1" border>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              名称
            </template>
            {{ idpLogContent.Name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              描述
            </template>
            {{ idpLogContent.Description }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              CPUID
            </template>
            {{ idpLogContent.ProcessorId }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              最大处理速度
            </template>
            {{ idpLogContent.MaxClockSpeed }} MHz
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              制造商
            </template>
            {{ idpLogContent.Manufacturer }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              二级缓存
            </template>
            {{ idpLogContent.L2CacheSize }} KB
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              三级缓存
            </template>
            {{ idpLogContent.L3CacheSize }} KB
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="内存信息" name="memory">
        <el-descriptions class="margin-top" title="数据来源与插件: memory" border>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              内存条个数
            </template>
            合计内存条个数：{{ idpLogContent.length }} 条
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions
          class="margin-top"
          :column="2"
          border
          v-for="(item, index) in idpLogContent"
          :key="index"
          :value="item"
        >
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              大小
            </template>
            {{ Math.floor(item.Capacity / (1024 * 1024 * 1024)) }} GB
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              描述
            </template>
            {{ item.Description }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              读写速度
            </template>
            {{ item.Speed }} MHz
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              序列号
            </template>
            {{ item.SerialNumber }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              生产商
            </template>
            {{ item.Manufacturer }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              电压配置
            </template>
            {{ item.ConfiguredVoltage }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              数据字长
            </template>
            {{ item.DataWidth }}
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="硬盘信息" name="disk">
        <el-descriptions class="margin-top" title="数据来源与插件: disk" border>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              硬盘个数
            </template>
            合计物理硬盘个数：{{ idpLogContent.length }} 块
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions
          class="margin-top"
          :column="2"
          border
          v-for="(item, index) in idpLogContent"
          :key="index"
          :value="item"
        >
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              大小
            </template>
            {{ Math.floor(item.Size / (1024 * 1024 * 1024)) }} GB
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              描述
            </template>
            {{ item.Model }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              类型
            </template>
            {{ item.MediaType }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              序列号
            </template>
            {{ item.SerialNumber }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              接口类型
            </template>
            {{ item.InterfaceType }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              每个扇区字节数
            </template>
            {{ item.BytesPerSector }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              厂商驱动固件信息
            </template>
            {{ item.FirmwareRevision }}
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="逻辑分区" name="logicDisk">
        <el-descriptions class="margin-top" title="数据来源与插件: disk" border>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              硬盘个数
            </template>
            合计物理硬盘个数：{{ idpLogContent.length }} 块
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions
          class="margin-top"
          :column="2"
          border
          v-for="(item, index) in idpLogContent"
          :key="index"
          :value="item"
        >
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              大小
            </template>
            {{ Math.floor(item.Size / (1024 * 1024 * 1024)) }} GB
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              盘符(名称)
            </template>
            {{ item.DeviceID + '(' + item.VolumeName + ')' }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              文件系统类型
            </template>
            {{ item.FileSystem }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              逻辑卷序列号
            </template>
            {{ item.VolumeSerialNumber }}
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="主板信息" name="board">
        <el-descriptions class="margin-top" title="数据来源: IDP调用WMI获取" :column="1" border>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              描述
            </template>
            {{ idpLogContent.Description }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              产品型号
            </template>
            {{ idpLogContent.Product }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              制造商
            </template>
            {{ idpLogContent.Manufacturer }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              序列号
            </template>
            {{ idpLogContent.SerialNumber }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              热插拔支持
            </template>
            {{ idpLogContent.HotSwappable }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              核心主板
            </template>
            {{ idpLogContent.HostingBoard }}
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="系统概述" name="sys">
        <el-descriptions
          class="margin-top"
          title="数据来源与插件：board ,参数为：base"
          :column="1"
          border
        >
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              主机名称
            </template>
            {{ idpLogContent.DNSHostName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-mobile-phone" />
              域
            </template>
            {{ idpLogContent.Domain }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-mobile-phone" />
              制造商
            </template>
            {{ idpLogContent.Manufacturer }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-mobile-phone" />
              型号
            </template>
            {{ idpLogContent.Model }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-mobile-phone" />
              是否入域
            </template>
            {{ idpLogContent.PartOfDomain }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-mobile-phone" />
              系统类型
            </template>
            {{ idpLogContent.SystemType }}
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="网卡信息" name="allMac">
        <el-descriptions class="margin-top" title="数据来源与插件: allMac" border>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              网卡数量
            </template>
            合计网卡数量：{{ idpLogContent.length }} 块
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions
          class="margin-top"
          :column="2"
          border
          v-for="(item, index) in idpLogContent"
          :key="index"
          :value="item"
        >
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              网卡地址
            </template>
            {{ item.MACAddress }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              名称
            </template>
            {{ item.Name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              默认网关
            </template>
            {{ item.DefaultIPGateway }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template v-slot:label>
              <i class="el-icon-user" />
              IP地址
            </template>
            {{ item.IPAddress }}
          </el-descriptions-item>
        </el-descriptions>
      </el-tab-pane>
      <el-tab-pane label="软件列表" name="service">
        <el-table :data="serviceList" style="width: 100%" max-height="400">
          <el-table-column label="服务名称" prop="Name" show-overflow-tooltip />
          <el-table-column label="显示名称" prop="DisplayName" show-overflow-tooltip />
          <el-table-column label="状态" prop="State" max-width="40" />
          <el-table-column label="启动方式" prop="StartMode" max-width="40" />
          <el-table-column label="路径" prop="PathName" show-overflow-tooltip />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="开机启动项" name="boot">
        <el-table :data="bootList" style="width: 100%" max-height="400">
          <el-table-column label="名称" prop="Name" show-overflow-tooltip />
          <el-table-column label="描述" prop="Description" show-overflow-tooltip />
          <el-table-column label="启动指令" prop="Command" show-overflow-tooltip />
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </el-dialog>
</template>

<style scoped></style>
